package com.yixun.qfbao.job;

import com.yixun.qfbao.api.service.ReportCommonService;
import com.yixun.qfbao.dao.ApiFailLogDao;
import com.yixun.qfbao.model.ApiFailLog;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author liuqi
 */
@Component
public class SendM2AgainJob {
    private static Logger logger = LoggerFactory.getLogger(SendM2AgainJob.class);

    @Autowired
    private ApiFailLogDao apiFailLogDao;

    @Autowired
    private ReportCommonService reportCommonService;

    @Scheduled(cron = "0 0/5 * * * ?")
    public void sendM2Again() {
        logger.info("sendM2Again  重新推送失败消息至m2 每5分钟一次");
        List<ApiFailLog> list = apiFailLogDao.listApiFailLogBySendM2Again();
        if (CollectionUtils.isNotEmpty(list)){
            int successCount = 0;
            logger.info("sendM2Again ------------------ list count :" + list.size());
            for (ApiFailLog apiFailLog : list){
               int count = reportCommonService.customerToM2Again(apiFailLog);
               successCount = successCount + count;
            }
            logger.info("sendM2Again 重新推送成功数量 count :" + successCount);
        }
    }
}
